日本語版Rails Girls Guideを素振りする
#2019-10-30
まだmacでやってなかったのでやる
Railsインストールガイド
code:sh
$ rbenv versions
* system (set by /Users/tanaka.kentaro/.rbenv/version)
2.5.3
はい
code:sh
$ rbenv install 2.6.5
ruby-build: definition not found: 2.6.5
See all available versions with `rbenv install --list'.
If the version you need is missing, try upgrading ruby-build:
brew update && brew upgrade ruby-build
$ rbenv install --list したら 2.6.3 までしかなかった
言われた通り $ brew update && brew upgrade ruby-build してみる
2.6.5まで出てきた👏
code:sh
$ rbenv install 2.6.5
ruby-build: using openssl from homebrew
Downloading ruby-2.6.5.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.5.tar.bz2
Installing ruby-2.6.5...
ruby-build: using readline from homebrew
Installed ruby-2.6.5 to /Users/tanaka.kentaro/.rbenv/versions/2.6.5
OK!
code:bash
$ brew install yarn
$ gem install rails --no-document
このワークショップでは Atom エディタを推奨しています。
まじか〜だるいな
一旦パスで...
動作確認
code:sh
$ rails new sample
$ cd sample
$ rails g scaffold book
$ rails db:migrate
$ rails server
OK。消す
$ cd .. && rm -rf sample/
はじめてのRailsアプリ
code:sh
$ rails new railsgirls
$ cd railsgirls
$ rails server
はい
code:sh
$ rails generate scaffold idea name:string description:text picture:string
$ rails db:migrate
$ rails server
http://localhost:3000/ideas にアクセス。OK
bootstrap, ヘッダーフッターデザインの追加、CSSの追加。OK
gem 'carrierwave' 追加
code:sh
$ bundle
$ rails generate uploader Picture
model, form, view(show)の修正OK
code:sh
$ rails generate controller pages info
はい
GitHubであなたのコードを公開しよう
code:sh
$ git config --local user.name "tanaken"
$ git config --local user.email "tanaka.kentaro.kk1222@gmail.com"
ユーザ名とメアドはlocalで設定しておいた
code:sh
$ echo public/uploads >> .gitignore
$ git add .
$ git commit -m "first commit"
$ git remote add origin git@github.com:tanaken0515/rails-girls-for-mac.git
$ git push -u origin master
あなたのアプリをインターネットに公開しよう
herokuでやる
#2019-10-06
rails new したので、scaffoldしていくぞ〜
tanaken0515/rails-girls-for-aws-cloud9-ubuntu
herokuにアップするやつやる?
Heroku CLI を ubuntuに入れる - Qiita
https://rails-girls-for-c9-ubuntu.herokuapp.com/ やった
Guard against DNS rebinding attacks by permitting hosts by gsamokovarov · Pull Request #33145 · rails/rails
config.hostsに追加するの、git管理しないほうがよかったかなぁ。やっちゃったけど。
別の方法でできそうな気がするんだよなぁ
#2019-10-05
ガイドの「RVM をアンインストールする」コマンドを確認する
さて、あえてガイド通りのコマンドをやってみよう
code:sh
$ /usr/bin/sudo rm -rf $HOME/.rvm $HOME/.rvmrc /etc/rvmrc /etc/profile.d/rvm.sh /usr/local/rvm /usr/local/bin/rvm
エラーは出ないんだなぁ
code:sh
$ /usr/bin/sudo /usr/sbin/groupdel rvm
groupdel: group 'rvm' does not exist
これは想定通り。groupなかったもんね
code:sh
$ sed -i -e '/rvm/d' ~/.bashrc
これはガイドの「RVM をアンインストールする」コマンドを確認する#5d97e923310c62000017946cと比べると
14行目 rvm_silence_path_mismatch_check_flag=1 # prevent rvm complaints that nvm is first in PATH
最終行 export PATH="$PATH:$HOME/.rvm/bin"
が消えてる
Cloud9 を再起動して操作を反映させる これはどうやってやるんだろ
EC2の再起動でいいのかな
Manage EC2 Instance でEC2の管理画面を開く
https://gyazo.com/03aa17ecda08868e843dd959ca8b58e4
https://gyazo.com/323a5eeddb51e510e73eadebbf1ea652
「再起動」やったけど「やったか....!?」という感じだったので「停止」と「開始」もした。
code:sh
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo 'PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ rbenv install 2.6.5
$ rbenv global 2.6.5
$ rbenv versions
system
* 2.6.5 (set by /home/ec2-user/.rbenv/version)
$ gem install bundler --no-document
$ gem install rails --no-document
おっけ〜い
Cloud9を再起動して $GEM_HOME, $GEM_PATH を更新します。 の確認をする。確認用に "test" environmentを作った。
再起動前
code:sh
$ echo $GEM_HOME
/home/ec2-user/.rvm/gems/ruby-2.6.3
$ echo $GEM_PATH
/home/ec2-user/.rvm/gems/ruby-2.6.3:/home/ec2-user/.rvm/gems/ruby-2.6.3@global
変更後
code:sh
$ echo $GEM_HOME
$ echo $GEM_PATH
update "using-a-cloud-service-c9" by tanaken0515 · Pull Request #480 · railsgirls-jp/railsgirls-jp.github.io プルリク出した!
Rails Girls アプリ・チュートリアル をやってく
rails new したら yarn をインストールしてなかったことに気づいた
AmazonLinuxにyarnをインストールする - Qiita や Installation | Yarn を見つつ
code:sh
$ wget --version # wgetは入ってるので使える
$ /usr/bin/sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
$ /usr/bin/sudo yum install yarn
$ yarn --version
1.19.0
いけた。理解は微妙。
rails server -b 0.0.0.0 -> Preview で Yay! が出なくて死んでる
サーバーにアクセスできない〜〜という気持ちで調べていたけど、これ冷静になったらRailsのエラー表示じゃん、つまりサーバーにはアクセスできているけどエラーが出ているということじゃん、と気づく。
config/application.rb に config.hosts << '.amazonaws.com' を追記
Railsを5.2から6.0へアップデートする時にハマったポイント - Qiita ホストを指定しないといけないのかぁ
Your version of SQLite (3.7.17) is too old. Active Record supports SQLite >= 3.8.
今度はSQLiteかい。
CentOS環境でRails6.0をSQLite3 (>=3.8)で動かす - Qiita ほう?
現時点(2019/9月)でCentOSで提供されているSQLiteのパッケージは3.7が最新であり、
Amazon Linux 2でSQLite3を最新バージョンにする - Qiita
Amazon LinuxのイメージはすでにSQLite3がインストール済みですが、バージョンが3.7.17 と少し古めです。
ruby on rails - Error Your version of SQLite (3.7.17) is too old. Active Record supports SQLite >= 3.8 - Stack Overflow
Oh cool I use Cloud9 as well. I would create another environment, after the title, hit next step, on the second page near the bottom has Amazon Linux or Ubuntu Server 18.04 LTS option. Pick Ubuntu and you'll be up and running.
なるほどな、ubuntu使えば?って言われてる。まじか〜w
ubuntuでやり直してる
code:sh
bash < <(curl -sL https://raw.github.com/railsgirls/installation-scripts/master/rails-install-ubuntu.sh)
curlはあったからね。楽チン。
code:sh
$ source ~/.rvm/scripts/rvm
$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) x86_64-linux
$ rails -v
Rails 6.0.0
#2019-10-04
4. 標準でインストールされている RVM をアンインストールする をやってく
ガイドには /usr/bin/sudo rm -rf $HOME/.rvm $HOME/.rvmrc /etc/rvmrc /etc/profile.d/rvm.sh /usr/local/rvm /usr/local/bin/rvm を実行しろと書いてるけど、それぞれのファイルがあるか確認しよう
ls -la $HOME/.rvm ある
ls -la $HOME/.rvmrc ない
ls -la /etc/rvmrc ない
ls -la /etc/profile.d/rvm.sh ない
ls -la /usr/local/rvm ない
ls -la /usr/local/bin/rvm ない
どうしような、一つ目だけやるか?
/usr/bin/sudo /usr/sbin/groupdel rvm これ何やってるん
sed -i -e '/rvm/d' ~/.bashrc これ(ry
#2019-10-03
まずは Rails Girls インストール・レシピ をやってく
Cloud9を担当することになったので、やる。
AWS Cloud9 のアカウントを作ってIDEを開くところまで やった